package com.woniu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniu.entity.PageBean;
import com.woniu.entity.Project;
import com.woniu.mapper.ProjectMapper;
import com.woniu.service.IProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> implements IProjectService {

    @Autowired
    private ProjectMapper projectMapper;
    @Override
    public PageBean<Project> getByPage(Project project , int page) {
        PageBean<Project> pageBean=new PageBean<>();
        Page<Project> p= PageHelper.startPage(page,2);//p
        List<Project> data=projectMapper.getByCondition(project);//data
        pageBean.setData(data);//data
        pageBean.setCurrPage(page);
        pageBean.setCurrPageSize(data.size());
        pageBean.setPageSize(2);
        pageBean.setTotalNums((int)p.getTotal());//p
        pageBean.setTotalPages(p.getPages());

        return pageBean;
    }

    @Override
    public void add(Project project) {
        projectMapper.add(project);
    }

    @Override
    public List<Project> getAll() {
        return projectMapper.getAll();
    }

    @Override
    public void update(Project project) {
        projectMapper.update(project);
    }

    @Override
    public Project getByProId(int proId) {
        return projectMapper.getByProId(proId);
    }

    @Override
    public List<Project> getByCondition(Project project) {
        return projectMapper.getByCondition(project);
    }

    @Override
    public Integer getNumsByProStatusAndProId(Project project) {
        return projectMapper.getNumsByProStatusAndProId(project);
    }

    @Override
    public List<Project> getProjectByProStatusAndProId(Project project) {
        return projectMapper.getProjectByProStatusAndProId(project);
    }

    @Override
    public void ppass(int proid) {
        projectMapper.ppass(proid);
    }

    @Override
    public void punpass(int proid) {
        projectMapper.punpass(proid);
    }

    @Override
    public void endpro(int proid, String endtime) {
        projectMapper.endpro(proid,endtime);
    }

    //新建项目
    @Override
    public void insertPro(Project project) {
        projectMapper.insertPro(project);
    }


    //重新提交,项目id不变，内容改变
    @Override
    public void reSubmit(Project project) {
        projectMapper.reSubmit(project);
    }

}
